<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>className</title>
</head>
<body>
    <div class="like">
        this is a div!
    </div>
    <div class="so">
        this is a div , too!
    </div>
    <script>

//        方法一：使用自定义的函数先遍历所有节点，用attr的方法取出class名字进行比对然后取出。
        function getElementsByClass(classnames){
            var classObj = new Array();
            var classInt = 0;
            var tags =document.getElementsByTagName("*");
            for(var i in tags){
                if(tags[i].nodeType == 1){
                    if(tags[i].getAttribute("class") == classnames){
                        classObj[classInt] = tags[i];
                        classInt++;
                    }
                }
            }
            return classObj;


        }
        var newFun = getElementsByClass('so');

        console.log(newFun);
//        方法二，直接使用getElementsByClassName方法
        var old = document.getElementsByClassName('like');
        console.log(old);
    </script>
</body>
</html>